package com.syf;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.tio.core.Tio;
import org.tio.websocket.common.WsResponse;
import org.tio.websocket.starter.EnableTioWebSocketServer;
import org.tio.websocket.starter.TioWebSocketServerBootstrap;

import java.util.Date;


@SpringBootApplication
@EnableTioWebSocketServer // 开启tio的websocket
@EnableScheduling  //定时任务
public class ChanServiceApplication {

    @Autowired
    private TioWebSocketServerBootstrap bootstrap ;

    public static void main(String[] args) {
        SpringApplication.run(ChanServiceApplication.class ,args) ;
    }


    /**
     * 每 5 s 给前端主动推送数据
     */
   /* @Scheduled(fixedRate = 5000)
    public void pushData(){
        long time = new Date().getTime();
        // 使用 Tio 推送数据非常简单
        Tio.sendToGroup(bootstrap.getServerTioConfig(),"test", WsResponse.fromText("现在 是:"+time , "utf-8"));
    }*/

}
